﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GraduationProject.RDBMS
{
    public class SortList : OpearteBase
    {
        /// <summary>
        /// 添加景区种类
        /// </summary>
        /// <param name="ExcuteResult"></param>
        /// <param name="SortLists"></param>
        /// <returns></returns>
        public bool TryInsertSortList(out bool ExcuteResult, params Model.SortList[] SortLists)
        {
            ExcuteResult = false;
            try
            {
                if (SortLists != null && SortLists.Count() > 0)
                {

                    //打开数据库事务
                    TryOpenTrans();
                    //更新数据库
                    StringBuilder Str_SQL = new StringBuilder();
                    #region 封装SQL语句
                    Str_SQL.AppendLine("INSERT INTO [dbo].[SortList]");
                    Str_SQL.AppendLine("([SortName]");
                    Str_SQL.AppendLine(",[CityID]");
                    Str_SQL.AppendLine(",[ScenicLevelID]");
                    Str_SQL.AppendLine(",[Picture]");
                    Str_SQL.AppendLine(",[Instructions]");
                    Str_SQL.AppendLine(",[PlaceX]");
                    Str_SQL.AppendLine(",[PlaceY]");
                    Str_SQL.AppendLine(",[Remark])");
                    Str_SQL.AppendLine("VALUES");
                    Str_SQL.AppendLine("(@SortName");
                    Str_SQL.AppendLine(",@CityID");
                    Str_SQL.AppendLine(",@ScenicLevelID");
                    Str_SQL.AppendLine(",@Picture");
                    Str_SQL.AppendLine(",@Instructions");
                    Str_SQL.AppendLine(",@PlaceX");
                    Str_SQL.AppendLine(",@PlaceY");
                    Str_SQL.AppendLine(",@Remark)");
                    #endregion

                    if (m_Conn.Execute(Str_SQL.ToString(), SortLists, m_Transaction) > 0)
                    {
                        ExcuteResult = true;
                        IsDone &= true;
                    }
                    else
                    {
                        ExcuteResult = false;
                        IsDone &= false;
                    }
                }
            }

            catch (Exception ex)
            {
                IsDone &= false;
                Console.WriteLine(ex);
            }
            return IsDone;
        }
        /// <summary>
        /// 删除景区种类
        /// </summary>
        /// <param name="ExcuteResult"></param>
        /// <param name="SortListIDs"></param>
        /// <returns></returns>
        public bool TryDeleteSortList(out bool ExcuteResult, params int[] SortListIDs)
        {
            ExcuteResult = false;
            try
            {
                if (SortListIDs != null && SortListIDs.Length > 0)
                {
                    StringBuilder Str_SQL = new StringBuilder();
                    #region 封装SQL语句
                    Str_SQL.AppendLine("DELETE FROM [dbo].[SortList]");
                    Str_SQL.AppendLine("WHERE [dbo].[SortList].[SortID] IN @IDs");
                    #endregion

                    TryOpenTrans();
                    if (m_Conn.Execute(Str_SQL.ToString(), new { IDs = SortListIDs }, m_Transaction) > 0)
                    {
                        ExcuteResult = true;
                        IsDone &= true;
                    }
                    else
                    {
                        ExcuteResult = false;
                        IsDone &= false;
                    }
                }
            }
            catch (Exception ex)
            {
                IsDone &= false;
                Console.WriteLine(ex);
            }
            return IsDone;
        }
        /// <summary>
        /// 修改景区信息
        /// </summary>
        /// <param name="ExcuteResult"></param>
        /// <param name="SortLists"></param>
        /// <returns></returns>
        public bool TryUpdateSortList(out bool ExcuteResult, params Model.SortList[] SortLists)
        {
            ExcuteResult = false;
            try
            {
                if (SortLists != null && SortLists.Length > 0)
                {
                    StringBuilder Str_SQL = new StringBuilder();
                    #region 封装SQL语句
                    Str_SQL.AppendLine("UPDATE [dbo].[SortList]");
                    Str_SQL.AppendLine("SET [SortName] = @SortName");
                    Str_SQL.AppendLine(",[CityID] = @CityID");
                    Str_SQL.AppendLine(",[ScenicLevelID] = @ScenicLevelID");
                    Str_SQL.AppendLine(",[Picture] = @Picture");
                    Str_SQL.AppendLine(",[Instructions] = @Instructions");
                    Str_SQL.AppendLine(",[PlaceX] = @PlaceX");
                    Str_SQL.AppendLine(",[PlaceY] = @PlaceY");
                    Str_SQL.AppendLine(",[Remark] = @Remark");
                    Str_SQL.AppendLine(" WHERE  [dbo].[SortList].[SortID] = @SortID");
                    #endregion

                    TryOpenTrans();
                    if (m_Conn.Execute(Str_SQL.ToString(), SortLists, m_Transaction) > 0)
                    {
                        ExcuteResult = true;
                        IsDone &= true;
                    }
                    else
                    {
                        ExcuteResult = false;
                        IsDone &= false;
                    }
                }
            }
            catch (Exception ex)
            {
                IsDone &= false;
                Console.WriteLine(ex);
            }
            return IsDone;
        }
        /// <summary>
        /// 查询景区信息
        /// </summary>
        /// <param name="SortLists"></param>
        /// <param name="SortIDs"></param>
        /// <returns></returns>
        public bool TrySelectSortList(out Model.SortList[] SortLists, int[] SortIDs = null, int[] ProvinceIDs = null, int[] CityIDs = null, int[] ScenicLevelIDs = null)
        {
            //预先定义返回值
            SortLists = null;
            try
            {
                StringBuilder Str_SQL_Where = new StringBuilder();
                #region 封装Where条件语句
                if (SortIDs != null && SortIDs.Length > 0)
                {
                    if (Str_SQL_Where.Length == 0)
                    {
                        Str_SQL_Where.AppendLine("WHERE");
                    }
                    if (Str_SQL_Where.Length > 7)
                    {
                        Str_SQL_Where.AppendLine("AND");
                    }
                    if (Str_SQL_Where.Length >= 7)
                    {
                        Str_SQL_Where.AppendLine("[dbo].[SortList].[SortID] IN @SortIDs");
                    }
                }
                if (ProvinceIDs != null && ProvinceIDs.Length > 0)
                {
                    if (Str_SQL_Where.Length == 0)
                    {
                        Str_SQL_Where.AppendLine("WHERE");
                    }
                    if (Str_SQL_Where.Length > 7)
                    {
                        Str_SQL_Where.AppendLine("AND");
                    }
                    if (Str_SQL_Where.Length >= 7)
                    {
                        Str_SQL_Where.AppendLine("dbo.Province.ProvinceID IN @ProvinceIDs");
                    }
                }
                if (CityIDs != null && CityIDs.Length > 0)
                {
                    if (Str_SQL_Where.Length == 0)
                    {
                        Str_SQL_Where.AppendLine("WHERE");
                    }
                    if (Str_SQL_Where.Length > 7)
                    {
                        Str_SQL_Where.AppendLine("AND");
                    }
                    if (Str_SQL_Where.Length >= 7)
                    {
                        Str_SQL_Where.AppendLine("dbo.City.CityID IN @CityIDs");
                    }
                }
                if (ScenicLevelIDs != null && ScenicLevelIDs.Length > 0)
                {
                    if (Str_SQL_Where.Length == 0)
                    {
                        Str_SQL_Where.AppendLine("WHERE");
                    }
                    if (Str_SQL_Where.Length > 7)
                    {
                        Str_SQL_Where.AppendLine("AND");
                    }
                    if (Str_SQL_Where.Length >= 7)
                    {
                        Str_SQL_Where.AppendLine("dbo.ScenicLevel.ScenicLevelID IN @ScenicLevelIDs");
                    }
                }
                #endregion

                StringBuilder Str_Sql = new StringBuilder();
                #region 封装SQL语句
                Str_Sql.AppendLine("SELECT");
                Str_Sql.AppendLine("dbo.SortList.SortID,");
                Str_Sql.AppendLine("dbo.SortList.SortName,");
                Str_Sql.AppendLine("dbo.SortList.CityID,");
                Str_Sql.AppendLine("dbo.SortList.ScenicLevelID,");
                Str_Sql.AppendLine("dbo.SortList.Picture,");
                Str_Sql.AppendLine("dbo.SortList.Instructions,");
                Str_Sql.AppendLine("dbo.SortList.PlaceX,");
                Str_Sql.AppendLine("dbo.SortList.PlaceY,");
                Str_Sql.AppendLine("dbo.SortList.Remark,");
                Str_Sql.AppendLine("dbo.City.CityID,");
                Str_Sql.AppendLine("dbo.City.CityName,");
                Str_Sql.AppendLine("dbo.Province.ProvinceID,");
                Str_Sql.AppendLine("dbo.Province.ProvinceName,");
                Str_Sql.AppendLine("dbo.ScenicLevel.ScenicLevelID,");
                Str_Sql.AppendLine("dbo.ScenicLevel.ScenicLevelName");
                Str_Sql.AppendLine("FROM");
                Str_Sql.AppendLine("dbo.SortList");
                Str_Sql.AppendLine("INNER JOIN dbo.City ON dbo.SortList.CityID = dbo.City.CityID");
                Str_Sql.AppendLine("INNER JOIN dbo.Province ON dbo.City.ProvinceID = dbo.Province.ProvinceID");
                Str_Sql.AppendLine("INNER JOIN dbo.ScenicLevel ON dbo.SortList.ScenicLevelID = dbo.ScenicLevel.ScenicLevelID");

                //判断是否存在查询条件
                if (Str_SQL_Where.Length > 0)
                {
                    Str_Sql.Append(Str_SQL_Where);
                }
                #endregion

                var SQL_Data = m_Conn.Query<Model.SortList>(Str_Sql.ToString(), new { SortIDs, ProvinceIDs, CityIDs, ScenicLevelIDs }, m_Transaction);
                if (SQL_Data != null && SQL_Data.Count() > 0)
                {
                    SortLists = SQL_Data.ToArray();
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return false;
        }
        /// <summary>
        /// 分页查询景区信息
        /// </summary>
        /// <returns></returns>
        public bool TrySelectSortListByPage(out Model.SortList[] Novels, out int TotalItemCount, int PageNumber = 1, int PageSize = 20, int[] SortIDs = null, int[] ProvinceIDs = null, int[] CityIDs = null, int[] ScenicLevelIDs = null)
        {
            //预先赋初始值
            Novels = null;
            TotalItemCount = 0;
            try
            {
                StringBuilder Str_SQL_Where = new StringBuilder();
                #region 封装Where条件语句
                if (SortIDs != null && SortIDs.Length > 0)
                {
                    if (Str_SQL_Where.Length == 0)
                    {
                        Str_SQL_Where.AppendLine("WHERE");
                    }
                    if (Str_SQL_Where.Length > 7)
                    {
                        Str_SQL_Where.AppendLine("AND");
                    }
                    if (Str_SQL_Where.Length >= 7)
                    {
                        Str_SQL_Where.AppendLine("[dbo].[SortList].[SortID] IN @SortIDs");
                    }
                }
                if (ProvinceIDs != null && ProvinceIDs.Length > 0)
                {
                    if (Str_SQL_Where.Length == 0)
                    {
                        Str_SQL_Where.AppendLine("WHERE");
                    }
                    if (Str_SQL_Where.Length > 7)
                    {
                        Str_SQL_Where.AppendLine("AND");
                    }
                    if (Str_SQL_Where.Length >= 7)
                    {
                        Str_SQL_Where.AppendLine("dbo.Province.ProvinceID IN @ProvinceIDs");
                    }
                }
                if (CityIDs != null && CityIDs.Length > 0)
                {
                    if (Str_SQL_Where.Length == 0)
                    {
                        Str_SQL_Where.AppendLine("WHERE");
                    }
                    if (Str_SQL_Where.Length > 7)
                    {
                        Str_SQL_Where.AppendLine("AND");
                    }
                    if (Str_SQL_Where.Length >= 7)
                    {
                        Str_SQL_Where.AppendLine("dbo.City.CityID IN @CityIDs");
                    }
                }
                if (ScenicLevelIDs != null && ScenicLevelIDs.Length > 0)
                {
                    if (Str_SQL_Where.Length == 0)
                    {
                        Str_SQL_Where.AppendLine("WHERE");
                    }
                    if (Str_SQL_Where.Length > 7)
                    {
                        Str_SQL_Where.AppendLine("AND");
                    }
                    if (Str_SQL_Where.Length >= 7)
                    {
                        Str_SQL_Where.AppendLine("dbo.ScenicLevel.ScenicLevelID IN @ScenicLevelIDs");
                    }
                }
                #endregion

                StringBuilder Str_SQL_PageSelect = new StringBuilder();
                #region 封装查询语句
                Str_SQL_PageSelect.AppendLine("SELECT");
                Str_SQL_PageSelect.AppendLine("dbo.SortList.SortID,");
                Str_SQL_PageSelect.AppendLine("dbo.SortList.SortName,");
                Str_SQL_PageSelect.AppendLine("dbo.SortList.CityID,");
                Str_SQL_PageSelect.AppendLine("dbo.SortList.ScenicLevelID,");
                Str_SQL_PageSelect.AppendLine("dbo.SortList.Picture,");
                Str_SQL_PageSelect.AppendLine("dbo.SortList.Instructions,");
                Str_SQL_PageSelect.AppendLine("dbo.SortList.PlaceX,");
                Str_SQL_PageSelect.AppendLine("dbo.SortList.PlaceY,");
                Str_SQL_PageSelect.AppendLine("dbo.SortList.Remark,");
                Str_SQL_PageSelect.AppendLine("dbo.City.CityID,");
                Str_SQL_PageSelect.AppendLine("dbo.City.CityName,");
                Str_SQL_PageSelect.AppendLine("dbo.Province.ProvinceID,");
                Str_SQL_PageSelect.AppendLine("dbo.Province.ProvinceName,");
                Str_SQL_PageSelect.AppendLine("dbo.ScenicLevel.ScenicLevelID,");
                Str_SQL_PageSelect.AppendLine("dbo.ScenicLevel.ScenicLevelName");
                Str_SQL_PageSelect.AppendLine("FROM");
                Str_SQL_PageSelect.AppendLine("dbo.SortList");
                Str_SQL_PageSelect.AppendLine("INNER JOIN dbo.City ON dbo.SortList.CityID = dbo.City.CityID");
                Str_SQL_PageSelect.AppendLine("INNER JOIN dbo.Province ON dbo.City.ProvinceID = dbo.Province.ProvinceID");
                Str_SQL_PageSelect.AppendLine("INNER JOIN dbo.ScenicLevel ON dbo.SortList.ScenicLevelID = dbo.ScenicLevel.ScenicLevelID");

                //判断是否存在查询条件
                if (Str_SQL_Where.Length > 0)
                {
                    Str_SQL_PageSelect.Append(Str_SQL_Where);
                }

                Str_SQL_PageSelect.AppendLine("Order By [dbo].[SortList].[SortID] ASC OFFSET (@PageNumber - 1) * @PageSize ROW FETCH NEXT @PageSize ROW ONLY ");
                #endregion

                StringBuilder Str_SQL_SelectCount = new StringBuilder();
                #region 封装数量查询语句
                Str_SQL_SelectCount.AppendLine("SELECT");
                Str_SQL_SelectCount.AppendLine("Count([dbo].[SortList].[SortID])");
                Str_SQL_SelectCount.AppendLine("FROM");
                Str_SQL_SelectCount.AppendLine("[dbo].[SortList]");
                //判断是否存在查询条件
                if (Str_SQL_Where.Length > 0)
                {
                    Str_SQL_SelectCount.Append(Str_SQL_Where);
                }
                #endregion

                //获取总条数
                TotalItemCount = m_Conn.ExecuteScalar<int>(Str_SQL_SelectCount.ToString(), new
                {
                    PageNumber,
                    PageSize,
                    SortIDs,
                    ProvinceIDs,
                    CityIDs,
                    ScenicLevelIDs
                });

                //判断是否存在数据
                if (TotalItemCount == 0)
                {
                    return false;
                }

                //获取分页数据
                var SQL_Data = m_Conn.Query<Model.SortList>(Str_SQL_PageSelect.ToString(), new
                {
                    PageNumber,
                    PageSize,
                    SortIDs,
                    ProvinceIDs,
                    CityIDs,
                    ScenicLevelIDs
                });
                //判断是否存在数据
                if (SQL_Data != null && SQL_Data.Count() > 0)
                {
                    Novels = SQL_Data.ToArray();
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return false;
        }

        /// <summary>
        /// 查询下拉框，城市列表
        /// </summary>
        /// <param name="CityList"></param>
        /// <param name="ProvinceIDs"></param>
        /// <param name="CityIDs"></param>
        /// <returns></returns>
        public bool TryGetCiteList(out Model.Province[] CityList, int[] ProvinceIDs = null, int[] CityIDs = null)
        {
            //预先定义返回值
            CityList = null;
            try
            {
                StringBuilder Str_SQL_Where = new StringBuilder();
                #region 封装Where条件语句
                if (ProvinceIDs != null && ProvinceIDs.Length > 0)
                {
                    if (Str_SQL_Where.Length == 0)
                    {
                        Str_SQL_Where.AppendLine("WHERE");
                    }
                    if (Str_SQL_Where.Length > 7)
                    {
                        Str_SQL_Where.AppendLine("AND");
                    }
                    if (Str_SQL_Where.Length >= 7)
                    {
                        Str_SQL_Where.AppendLine("dbo.Province.ProvinceID IN @ProvinceIDs");
                    }
                }
                if (CityIDs != null && CityIDs.Length > 0)
                {
                    if (Str_SQL_Where.Length == 0)
                    {
                        Str_SQL_Where.AppendLine("WHERE");
                    }
                    if (Str_SQL_Where.Length > 7)
                    {
                        Str_SQL_Where.AppendLine("AND");
                    }
                    if (Str_SQL_Where.Length >= 7)
                    {
                        Str_SQL_Where.AppendLine("dbo.City.CityID IN @CityIDs");
                    }
                }
                #endregion

                StringBuilder Str_Sql = new StringBuilder();
                #region 封装SQL语句
                Str_Sql.AppendLine("SELECT");
                Str_Sql.AppendLine("dbo.Province.ProvinceID,");
                Str_Sql.AppendLine("dbo.Province.ProvinceName AS ProvincelName,");
                Str_Sql.AppendLine("dbo.City.CityID,");
                Str_Sql.AppendLine("dbo.City.ProvinceID,");
                Str_Sql.AppendLine("dbo.City.CityName");
                Str_Sql.AppendLine("FROM");
                Str_Sql.AppendLine("dbo.Province");
                Str_Sql.AppendLine("INNER JOIN dbo.City ON dbo.City.ProvinceID = dbo.Province.ProvinceID");

                //判断是否存在查询条件
                if (Str_SQL_Where.Length > 0)
                {
                    Str_Sql.Append(Str_SQL_Where);
                }
                #endregion

                var outPut = new Dictionary<int, Model.Province>();
                m_Conn.Query<Model.Province, Model.City, Model.Province>(Str_Sql.ToString(), (Temp_Province, Temp_City) =>
                {
                    if (Temp_Province != null)
                    {
                        if (!outPut.ContainsKey(Temp_Province.ProvinceID))
                        {
                            outPut.Add(Temp_Province.ProvinceID, Temp_Province);
                        }

                        if (Temp_City != null)
                        {
                            if (outPut[Temp_Province.ProvinceID].Cities == null)
                            {
                                outPut[Temp_Province.ProvinceID].Cities = new List<Model.City>();
                            }
                            else
                            {
                                outPut[Temp_Province.ProvinceID].Cities.Add(Temp_City);
                            }
                        }
                    }
                    return Temp_Province;
                }, new
                {
                    ProvinceIDs,
                    CityIDs
                }, splitOn: "ProvinceID,CityID", transaction: m_Transaction);

                if (outPut != null && outPut.Count > 0)
                {
                    CityList = outPut.Values.ToArray();
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return false;
        }
        /// <summary>
        /// 查询景区级别列表
        /// </summary>
        /// <param name="ScenicLevelList"></param>
        /// <param name="ScenicLevelIDs"></param>
        /// <returns></returns>
        public bool TryGetScenicLevelList(out Model.ScenicLevel[] ScenicLevelList, int[] ScenicLevelIDs = null)
        {
            //预先定义返回值
            ScenicLevelList = null;
            try
            {
                StringBuilder Str_SQL_Where = new StringBuilder();
                #region 封装Where条件语句
                if (ScenicLevelIDs != null && ScenicLevelIDs.Length > 0)
                {
                    if (Str_SQL_Where.Length == 0)
                    {
                        Str_SQL_Where.AppendLine("WHERE");
                    }
                    if (Str_SQL_Where.Length > 7)
                    {
                        Str_SQL_Where.AppendLine("AND");
                    }
                    if (Str_SQL_Where.Length >= 7)
                    {
                        Str_SQL_Where.AppendLine("dbo.ScenicLevel.ScenicLevelID IN @ScenicLevelIDs");
                    }
                }
                #endregion

                StringBuilder Str_Sql = new StringBuilder();
                #region 封装SQL语句
                Str_Sql.AppendLine("SELECT");
                Str_Sql.AppendLine("dbo.ScenicLevel.ScenicLevelID,");
                Str_Sql.AppendLine("dbo.ScenicLevel.ScenicLevelName");
                Str_Sql.AppendLine("FROM");
                Str_Sql.AppendLine("dbo.ScenicLevel");

                //判断是否存在查询条件
                if (Str_SQL_Where.Length > 0)
                {
                    Str_Sql.Append(Str_SQL_Where);
                }
                #endregion


                var SQL_Data = m_Conn.Query<Model.ScenicLevel>(Str_Sql.ToString(), new { ScenicLevelIDs }, m_Transaction);
                if (SQL_Data != null && SQL_Data.Count() > 0)
                {
                    ScenicLevelList = SQL_Data.ToArray();
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return false;
        }
        /// <summary>
        /// 搜索景区
        /// </summary>
        /// <returns></returns>
        public bool TryGetSortListBySearch(out Model.SortList[] SortLists, out decimal XPlace, out decimal YPlace, string SearchText = null)
        {
            //预先定义返回值
            SortLists = null;
            XPlace = 0;
            YPlace = 0;

            try
            {
                StringBuilder Str_SQL_Where = new StringBuilder();
                #region 封装Where条件语句
                if (!string.IsNullOrEmpty(SearchText))
                {
                    SearchText = "%" + SearchText + "%";
                    Str_SQL_Where.AppendLine("WHERE");
                    Str_SQL_Where.AppendLine("dbo.Province.ProvinceName LIKE @SearchText OR");
                    Str_SQL_Where.AppendLine("dbo.City.CityName LIKE @SearchText OR");
                    Str_SQL_Where.AppendLine("dbo.ScenicLevel.ScenicLevelName LIKE @SearchText OR");
                    Str_SQL_Where.AppendLine("dbo.SortList.SortName LIKE @SearchText");
                }
                #endregion

                StringBuilder Str_Sql = new StringBuilder();
                #region 封装SQL语句
                Str_Sql.AppendLine("SELECT");
                Str_Sql.AppendLine("dbo.SortList.SortID,");
                Str_Sql.AppendLine("dbo.SortList.SortName,");
                Str_Sql.AppendLine("dbo.SortList.CityID,");
                Str_Sql.AppendLine("dbo.SortList.ScenicLevelID,");
                Str_Sql.AppendLine("dbo.SortList.Picture,");
                Str_Sql.AppendLine("dbo.SortList.Instructions,");
                Str_Sql.AppendLine("dbo.SortList.PlaceX,");
                Str_Sql.AppendLine("dbo.SortList.PlaceY,");
                Str_Sql.AppendLine("dbo.SortList.Remark,");
                Str_Sql.AppendLine("dbo.City.CityID,");
                Str_Sql.AppendLine("dbo.City.CityName,");
                Str_Sql.AppendLine("dbo.Province.ProvinceID,");
                Str_Sql.AppendLine("dbo.Province.ProvinceName,");
                Str_Sql.AppendLine("dbo.ScenicLevel.ScenicLevelID,");
                Str_Sql.AppendLine("dbo.ScenicLevel.ScenicLevelName");
                Str_Sql.AppendLine("FROM");
                Str_Sql.AppendLine("dbo.SortList");
                Str_Sql.AppendLine("INNER JOIN dbo.City ON dbo.SortList.CityID = dbo.City.CityID");
                Str_Sql.AppendLine("INNER JOIN dbo.Province ON dbo.City.ProvinceID = dbo.Province.ProvinceID");
                Str_Sql.AppendLine("INNER JOIN dbo.ScenicLevel ON dbo.SortList.ScenicLevelID = dbo.ScenicLevel.ScenicLevelID");

                //判断是否存在查询条件
                if (Str_SQL_Where.Length > 0)
                {
                    Str_Sql.Append(Str_SQL_Where);
                }
                #endregion

                var SQL_Data = m_Conn.Query<Model.SortList>(Str_Sql.ToString(), new { SearchText }, m_Transaction);
                if (SQL_Data != null && SQL_Data.Count() > 0)
                {
                    SortLists = SQL_Data.ToArray();
                    XPlace = (SortLists.Max(p => p.PlaceX) + SortLists.Min(p => p.PlaceX)) / 2;
                    YPlace = (SortLists.Max(p => p.PlaceY) + SortLists.Min(p => p.PlaceY)) / 2;
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return false;
        }
    }
}
